Skip to content

feat: add discrete RV subtraction and division operators via FastRV#41

Merged
MthwRobinson merged 16 commits into
mainfrom
feat/rust-sub-div
Mar 30, 2026
Merged

feat: add discrete RV subtraction and division operators via FastRV#41
MthwRobinson merged 16 commits into
mainfrom
feat/rust-sub-div

Conversation

@MthwRobinson

Copy link
Copy Markdown
Owner

Description

This PR expands discrete random variable algebra across the Rust core and the Python API.

On the Rust side, it adds Sub, SubAssign, Div, DivAssign, and MulAssign support for
RandomVariable, using the discrete transform machinery to implement subtraction by negating the RHS
and division by multiplying by the transformed reciprocal. It also adds validation for discrete
transformations, including checks for empty transformation lists, invalid or non-adjacent ranges,
incomplete support coverage, and divide-by-zero support in RV division.

To support those operations, shared sorting and support de-duplication logic was extracted into a new
shared module and reused by convolution, product, mixture, and transform code. The branch also adds
doc tests and unit coverage for the new algebra operations and the shared helpers.

On the Python side, RV now routes discrete RV-to-RV +, -, *, and / operations through
FastRV, and the Rust-backed Python API now exposes the corresponding reflected and direct operator
methods. Error handling was updated so divide-by-zero and similar Rust-side failures surface as
ValueError, and the Python lint target was adjusted to run ruff with uv --no-sync.

Testing

Run the Rust checks and tests:

  • make cargo-check
  • make cargo-test

Run the Python checks and tests:

  • make check
  • make rust-develop
  • make test

@MthwRobinson MthwRobinson merged commit 1ba745e into main Mar 30, 2026
8 checks passed
@MthwRobinson MthwRobinson deleted the feat/rust-sub-div branch March 30, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant